<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>scapi.authentication</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  <script type="text/javascript" src="epydoc.js"></script>
</head>

<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="scapi-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            >SoundCloud API</th>
          </tr></table></th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <span class="breadcrumbs">
        <a href="scapi-module.html">Package&nbsp;scapi</a> ::
        Module&nbsp;authentication
      </span>
    </td>
    <td>
      <table cellpadding="0" cellspacing="0">
        <!-- hide/show private -->
        <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
    onclick="toggle_private();">hide&nbsp;private</a>]</span></td></tr>
        <tr><td align="right"><span class="options"
            >[<a href="frames.html" target="_top">frames</a
            >]&nbsp;|&nbsp;<a href="scapi.authentication-pysrc.html"
            target="_top">no&nbsp;frames</a>]</span></td></tr>
      </table>
    </td>
  </tr>
</table>
<h1 class="epydoc">Source Code for <a href="scapi.authentication-module.html">Module scapi.authentication</a></h1>
<pre class="py-src">
<a name="L1"></a><tt class="py-lineno">  1</tt>  <tt class="py-line"><tt class="py-comment">##    SouncCloudAPI implements a Python wrapper around the SoundCloud RESTful</tt> </tt>
<a name="L2"></a><tt class="py-lineno">  2</tt>  <tt class="py-line"><tt class="py-comment"></tt><tt class="py-comment">##    API</tt> </tt>
<a name="L3"></a><tt class="py-lineno">  3</tt>  <tt class="py-line"><tt class="py-comment"></tt><tt class="py-comment">##</tt> </tt>
<a name="L4"></a><tt class="py-lineno">  4</tt>  <tt class="py-line"><tt class="py-comment"></tt><tt class="py-comment">##    Copyright (C) 2008  Diez B. Roggisch</tt> </tt>
<a name="L5"></a><tt class="py-lineno">  5</tt>  <tt class="py-line"><tt class="py-comment"></tt><tt class="py-comment">##    Contact mailto:deets@soundcloud.com</tt> </tt>
<a name="L6"></a><tt class="py-lineno">  6</tt>  <tt class="py-line"><tt class="py-comment"></tt><tt class="py-comment">##</tt> </tt>
<a name="L7"></a><tt class="py-lineno">  7</tt>  <tt class="py-line"><tt class="py-comment"></tt><tt class="py-comment">##    This library is free software; you can redistribute it and/or</tt> </tt>
<a name="L8"></a><tt class="py-lineno">  8</tt>  <tt class="py-line"><tt class="py-comment"></tt><tt class="py-comment">##    modify it under the terms of the GNU Lesser General Public</tt> </tt>
<a name="L9"></a><tt class="py-lineno">  9</tt>  <tt class="py-line"><tt class="py-comment"></tt><tt class="py-comment">##    License as published by the Free Software Foundation; either</tt> </tt>
<a name="L10"></a><tt class="py-lineno"> 10</tt>  <tt class="py-line"><tt class="py-comment"></tt><tt class="py-comment">##    version 2.1 of the License, or (at your option) any later version.</tt> </tt>
<a name="L11"></a><tt class="py-lineno"> 11</tt>  <tt class="py-line"><tt class="py-comment"></tt><tt class="py-comment">##</tt> </tt>
<a name="L12"></a><tt class="py-lineno"> 12</tt>  <tt class="py-line"><tt class="py-comment"></tt><tt class="py-comment">##    This library is distributed in the hope that it will be useful,</tt> </tt>
<a name="L13"></a><tt class="py-lineno"> 13</tt>  <tt class="py-line"><tt class="py-comment"></tt><tt class="py-comment">##    but WITHOUT ANY WARRANTY; without even the implied warranty of</tt> </tt>
<a name="L14"></a><tt class="py-lineno"> 14</tt>  <tt class="py-line"><tt class="py-comment"></tt><tt class="py-comment">##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</tt> </tt>
<a name="L15"></a><tt class="py-lineno"> 15</tt>  <tt class="py-line"><tt class="py-comment"></tt><tt class="py-comment">##    Lesser General Public License for more details.</tt> </tt>
<a name="L16"></a><tt class="py-lineno"> 16</tt>  <tt class="py-line"><tt class="py-comment"></tt><tt class="py-comment">##</tt> </tt>
<a name="L17"></a><tt class="py-lineno"> 17</tt>  <tt class="py-line"><tt class="py-comment"></tt><tt class="py-comment">##    You should have received a copy of the GNU Lesser General Public</tt> </tt>
<a name="L18"></a><tt class="py-lineno"> 18</tt>  <tt class="py-line"><tt class="py-comment"></tt><tt class="py-comment">##    License along with this library; if not, write to the Free Software</tt> </tt>
<a name="L19"></a><tt class="py-lineno"> 19</tt>  <tt class="py-line"><tt class="py-comment"></tt><tt class="py-comment">##    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</tt> </tt>
<a name="L20"></a><tt class="py-lineno"> 20</tt>  <tt class="py-line"><tt class="py-comment"></tt> </tt>
<a name="L21"></a><tt class="py-lineno"> 21</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">base64</tt> </tt>
<a name="L22"></a><tt class="py-lineno"> 22</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">urllib2</tt> </tt>
<a name="L23"></a><tt class="py-lineno"> 23</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">time</tt><tt class="py-op">,</tt> <tt class="py-name">random</tt> </tt>
<a name="L24"></a><tt class="py-lineno"> 24</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">urlparse</tt> </tt>
<a name="L25"></a><tt class="py-lineno"> 25</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">hmac</tt> </tt>
<a name="L26"></a><tt class="py-lineno"> 26</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">hashlib</tt> </tt>
<a name="L27"></a><tt class="py-lineno"> 27</tt>  <tt class="py-line"><tt class="py-keyword">from</tt> <tt id="link-0" class="py-name" targets="Package scapi=scapi-module.html"><a title="scapi" class="py-name" href="#" onclick="return doclink('link-0', 'scapi', 'link-0');">scapi</a></tt><tt class="py-op">.</tt><tt id="link-1" class="py-name" targets="Module scapi.util=scapi.util-module.html"><a title="scapi.util" class="py-name" href="#" onclick="return doclink('link-1', 'util', 'link-1');">util</a></tt> <tt class="py-keyword">import</tt> <tt id="link-2" class="py-name" targets="Function scapi.util.escape()=scapi.util-module.html#escape"><a title="scapi.util.escape" class="py-name" href="#" onclick="return doclink('link-2', 'escape', 'link-2');">escape</a></tt> </tt>
<a name="L28"></a><tt class="py-lineno"> 28</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">logging</tt> </tt>
<a name="L29"></a><tt class="py-lineno"> 29</tt>  <tt class="py-line"> </tt>
<a name="L30"></a><tt class="py-lineno"> 30</tt>  <tt class="py-line"><tt id="link-3" class="py-name" targets="Variable scapi.authentication.logger=scapi.authentication-module.html#logger,Variable scapi.logger=scapi-module.html#logger,Variable scapi.tests.test_connect.logger=scapi.tests.test_connect-module.html#logger,Variable scapi.tests.test_oauth.logger=scapi.tests.test_oauth-module.html#logger"><a title="scapi.authentication.logger
scapi.logger
scapi.tests.test_connect.logger
scapi.tests.test_oauth.logger" class="py-name" href="#" onclick="return doclink('link-3', 'logger', 'link-3');">logger</a></tt> <tt class="py-op">=</tt> <tt class="py-name">logging</tt><tt class="py-op">.</tt><tt class="py-name">getLogger</tt><tt class="py-op">(</tt><tt class="py-name">__name__</tt><tt class="py-op">)</tt> </tt>
<a name="L31"></a><tt class="py-lineno"> 31</tt>  <tt class="py-line"> </tt>
<a name="OAuthSignatureMethod_HMAC_SHA1"></a><div id="OAuthSignatureMethod_HMAC_SHA1-def"><a name="L32"></a><tt class="py-lineno"> 32</tt> <a class="py-toggle" href="#" id="OAuthSignatureMethod_HMAC_SHA1-toggle" onclick="return toggle('OAuthSignatureMethod_HMAC_SHA1');">-</a><tt class="py-line"><tt class="py-keyword">class</tt> <a class="py-def-name" href="scapi.authentication.OAuthSignatureMethod_HMAC_SHA1-class.html">OAuthSignatureMethod_HMAC_SHA1</a><tt class="py-op">(</tt><tt class="py-base-class">object</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="OAuthSignatureMethod_HMAC_SHA1-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="OAuthSignatureMethod_HMAC_SHA1-expanded"><a name="L33"></a><tt class="py-lineno"> 33</tt>  <tt class="py-line"> </tt>
<a name="L34"></a><tt class="py-lineno"> 34</tt>  <tt class="py-line">    <tt id="link-4" class="py-name" targets="Variable scapi.authentication.OAuthSignatureMethod_HMAC_SHA1.FORBIDDEN=scapi.authentication.OAuthSignatureMethod_HMAC_SHA1-class.html#FORBIDDEN"><a title="scapi.authentication.OAuthSignatureMethod_HMAC_SHA1.FORBIDDEN" class="py-name" href="#" onclick="return doclink('link-4', 'FORBIDDEN', 'link-4');">FORBIDDEN</a></tt> <tt class="py-op">=</tt> <tt class="py-op">[</tt><tt class="py-string">'realm'</tt><tt class="py-op">,</tt> <tt class="py-string">'oauth_signature'</tt><tt class="py-op">]</tt> </tt>
<a name="L35"></a><tt class="py-lineno"> 35</tt>  <tt class="py-line"> </tt>
<a name="OAuthSignatureMethod_HMAC_SHA1.get_name"></a><div id="OAuthSignatureMethod_HMAC_SHA1.get_name-def"><a name="L36"></a><tt class="py-lineno"> 36</tt> <a class="py-toggle" href="#" id="OAuthSignatureMethod_HMAC_SHA1.get_name-toggle" onclick="return toggle('OAuthSignatureMethod_HMAC_SHA1.get_name');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="scapi.authentication.OAuthSignatureMethod_HMAC_SHA1-class.html#get_name">get_name</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="OAuthSignatureMethod_HMAC_SHA1.get_name-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="OAuthSignatureMethod_HMAC_SHA1.get_name-expanded"><a name="L37"></a><tt class="py-lineno"> 37</tt>  <tt class="py-line">        <tt class="py-keyword">return</tt> <tt class="py-string">'HMAC-SHA1'</tt> </tt>
</div><a name="L38"></a><tt class="py-lineno"> 38</tt>  <tt class="py-line"> </tt>
<a name="OAuthSignatureMethod_HMAC_SHA1.build_signature"></a><div id="OAuthSignatureMethod_HMAC_SHA1.build_signature-def"><a name="L39"></a><tt class="py-lineno"> 39</tt> <a class="py-toggle" href="#" id="OAuthSignatureMethod_HMAC_SHA1.build_signature-toggle" onclick="return toggle('OAuthSignatureMethod_HMAC_SHA1.build_signature');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="scapi.authentication.OAuthSignatureMethod_HMAC_SHA1-class.html#build_signature">build_signature</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt> <tt class="py-param">request</tt><tt class="py-op">,</tt> <tt class="py-param">parameters</tt><tt class="py-op">,</tt> <tt class="py-param">consumer_secret</tt><tt class="py-op">,</tt> <tt class="py-param">token_secret</tt><tt class="py-op">,</tt> <tt class="py-param">oauth_parameters</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="OAuthSignatureMethod_HMAC_SHA1.build_signature-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="OAuthSignatureMethod_HMAC_SHA1.build_signature-expanded"><a name="L40"></a><tt class="py-lineno"> 40</tt>  <tt class="py-line">        <tt class="py-name">temp</tt> <tt class="py-op">=</tt> <tt class="py-op">{</tt><tt class="py-op">}</tt> </tt>
<a name="L41"></a><tt class="py-lineno"> 41</tt>  <tt class="py-line">        <tt class="py-name">temp</tt><tt class="py-op">.</tt><tt class="py-name">update</tt><tt class="py-op">(</tt><tt class="py-name">oauth_parameters</tt><tt class="py-op">)</tt> </tt>
<a name="L42"></a><tt class="py-lineno"> 42</tt>  <tt class="py-line">        <tt class="py-keyword">for</tt> <tt class="py-name">p</tt> <tt class="py-keyword">in</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-5" class="py-name"><a title="scapi.authentication.OAuthSignatureMethod_HMAC_SHA1.FORBIDDEN" class="py-name" href="#" onclick="return doclink('link-5', 'FORBIDDEN', 'link-4');">FORBIDDEN</a></tt><tt class="py-op">:</tt> </tt>
<a name="L43"></a><tt class="py-lineno"> 43</tt>  <tt class="py-line">            <tt class="py-keyword">if</tt> <tt class="py-name">p</tt> <tt class="py-keyword">in</tt> <tt class="py-name">temp</tt><tt class="py-op">:</tt> </tt>
<a name="L44"></a><tt class="py-lineno"> 44</tt>  <tt class="py-line">                <tt class="py-keyword">del</tt> <tt class="py-name">temp</tt><tt class="py-op">[</tt><tt class="py-name">p</tt><tt class="py-op">]</tt> </tt>
<a name="L45"></a><tt class="py-lineno"> 45</tt>  <tt class="py-line">        <tt class="py-keyword">if</tt> <tt class="py-name">parameters</tt> <tt class="py-keyword">is</tt> <tt class="py-keyword">not</tt> <tt class="py-name">None</tt><tt class="py-op">:</tt> </tt>
<a name="L46"></a><tt class="py-lineno"> 46</tt>  <tt class="py-line">            <tt class="py-name">temp</tt><tt class="py-op">.</tt><tt class="py-name">update</tt><tt class="py-op">(</tt><tt class="py-name">parameters</tt><tt class="py-op">)</tt> </tt>
<a name="L47"></a><tt class="py-lineno"> 47</tt>  <tt class="py-line">        <tt class="py-name">sig</tt> <tt class="py-op">=</tt> <tt class="py-op">(</tt> </tt>
<a name="L48"></a><tt class="py-lineno"> 48</tt>  <tt class="py-line">            <tt id="link-6" class="py-name"><a title="scapi.util.escape" class="py-name" href="#" onclick="return doclink('link-6', 'escape', 'link-2');">escape</a></tt><tt class="py-op">(</tt><tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-7" class="py-name" targets="Method scapi.authentication.OAuthSignatureMethod_HMAC_SHA1.get_normalized_http_method()=scapi.authentication.OAuthSignatureMethod_HMAC_SHA1-class.html#get_normalized_http_method"><a title="scapi.authentication.OAuthSignatureMethod_HMAC_SHA1.get_normalized_http_method" class="py-name" href="#" onclick="return doclink('link-7', 'get_normalized_http_method', 'link-7');">get_normalized_http_method</a></tt><tt class="py-op">(</tt><tt class="py-name">request</tt><tt class="py-op">)</tt><tt class="py-op">)</tt><tt class="py-op">,</tt> </tt>
<a name="L49"></a><tt class="py-lineno"> 49</tt>  <tt class="py-line">            <tt id="link-8" class="py-name"><a title="scapi.util.escape" class="py-name" href="#" onclick="return doclink('link-8', 'escape', 'link-2');">escape</a></tt><tt class="py-op">(</tt><tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-9" class="py-name" targets="Method scapi.authentication.OAuthSignatureMethod_HMAC_SHA1.get_normalized_http_url()=scapi.authentication.OAuthSignatureMethod_HMAC_SHA1-class.html#get_normalized_http_url"><a title="scapi.authentication.OAuthSignatureMethod_HMAC_SHA1.get_normalized_http_url" class="py-name" href="#" onclick="return doclink('link-9', 'get_normalized_http_url', 'link-9');">get_normalized_http_url</a></tt><tt class="py-op">(</tt><tt class="py-name">request</tt><tt class="py-op">)</tt><tt class="py-op">)</tt><tt class="py-op">,</tt> </tt>
<a name="L50"></a><tt class="py-lineno"> 50</tt>  <tt class="py-line">            <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-10" class="py-name" targets="Method scapi.authentication.OAuthSignatureMethod_HMAC_SHA1.get_normalized_parameters()=scapi.authentication.OAuthSignatureMethod_HMAC_SHA1-class.html#get_normalized_parameters"><a title="scapi.authentication.OAuthSignatureMethod_HMAC_SHA1.get_normalized_parameters" class="py-name" href="#" onclick="return doclink('link-10', 'get_normalized_parameters', 'link-10');">get_normalized_parameters</a></tt><tt class="py-op">(</tt><tt class="py-name">temp</tt><tt class="py-op">)</tt><tt class="py-op">,</tt> <tt class="py-comment"># these are escaped in the method already</tt> </tt>
<a name="L51"></a><tt class="py-lineno"> 51</tt>  <tt class="py-line">        <tt class="py-op">)</tt> </tt>
<a name="L52"></a><tt class="py-lineno"> 52</tt>  <tt class="py-line">         </tt>
<a name="L53"></a><tt class="py-lineno"> 53</tt>  <tt class="py-line">        <tt class="py-name">key</tt> <tt class="py-op">=</tt> <tt class="py-string">'%s&amp;'</tt> <tt class="py-op">%</tt> <tt class="py-name">consumer_secret</tt> </tt>
<a name="L54"></a><tt class="py-lineno"> 54</tt>  <tt class="py-line">        <tt class="py-keyword">if</tt> <tt class="py-name">token_secret</tt> <tt class="py-keyword">is</tt> <tt class="py-keyword">not</tt> <tt class="py-name">None</tt><tt class="py-op">:</tt> </tt>
<a name="L55"></a><tt class="py-lineno"> 55</tt>  <tt class="py-line">            <tt class="py-name">key</tt> <tt class="py-op">+=</tt> <tt class="py-name">token_secret</tt> </tt>
<a name="L56"></a><tt class="py-lineno"> 56</tt>  <tt class="py-line">        <tt class="py-name">raw</tt> <tt class="py-op">=</tt> <tt class="py-string">'&amp;'</tt><tt class="py-op">.</tt><tt class="py-name">join</tt><tt class="py-op">(</tt><tt class="py-name">sig</tt><tt class="py-op">)</tt> </tt>
<a name="L57"></a><tt class="py-lineno"> 57</tt>  <tt class="py-line">        <tt id="link-11" class="py-name"><a title="scapi.authentication.logger
scapi.logger
scapi.tests.test_connect.logger
scapi.tests.test_oauth.logger" class="py-name" href="#" onclick="return doclink('link-11', 'logger', 'link-3');">logger</a></tt><tt class="py-op">.</tt><tt class="py-name">debug</tt><tt class="py-op">(</tt><tt class="py-string">"raw basestring: %s"</tt><tt class="py-op">,</tt> <tt class="py-name">raw</tt><tt class="py-op">)</tt> </tt>
<a name="L58"></a><tt class="py-lineno"> 58</tt>  <tt class="py-line">        <tt class="py-comment"># hmac object</tt> </tt>
<a name="L59"></a><tt class="py-lineno"> 59</tt>  <tt class="py-line"><tt class="py-comment"></tt>        <tt class="py-name">hashed</tt> <tt class="py-op">=</tt> <tt class="py-name">hmac</tt><tt class="py-op">.</tt><tt id="link-12" class="py-name" targets="Class Method scapi.RESTBase.new()=scapi.RESTBase-class.html#new"><a title="scapi.RESTBase.new" class="py-name" href="#" onclick="return doclink('link-12', 'new', 'link-12');">new</a></tt><tt class="py-op">(</tt><tt class="py-name">key</tt><tt class="py-op">,</tt> <tt class="py-name">raw</tt><tt class="py-op">,</tt> <tt class="py-name">hashlib</tt><tt class="py-op">.</tt><tt class="py-name">sha1</tt><tt class="py-op">)</tt> </tt>
<a name="L60"></a><tt class="py-lineno"> 60</tt>  <tt class="py-line">        <tt class="py-comment"># calculate the digest base 64</tt> </tt>
<a name="L61"></a><tt class="py-lineno"> 61</tt>  <tt class="py-line"><tt class="py-comment"></tt>        <tt class="py-name">signature</tt> <tt class="py-op">=</tt> <tt id="link-13" class="py-name"><a title="scapi.util.escape" class="py-name" href="#" onclick="return doclink('link-13', 'escape', 'link-2');">escape</a></tt><tt class="py-op">(</tt><tt class="py-name">base64</tt><tt class="py-op">.</tt><tt class="py-name">b64encode</tt><tt class="py-op">(</tt><tt class="py-name">hashed</tt><tt class="py-op">.</tt><tt class="py-name">digest</tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
<a name="L62"></a><tt class="py-lineno"> 62</tt>  <tt class="py-line">        <tt class="py-keyword">return</tt> <tt class="py-name">signature</tt> </tt>
</div><a name="L63"></a><tt class="py-lineno"> 63</tt>  <tt class="py-line"> </tt>
<a name="OAuthSignatureMethod_HMAC_SHA1.get_normalized_http_method"></a><div id="OAuthSignatureMethod_HMAC_SHA1.get_normalized_http_method-def"><a name="L64"></a><tt class="py-lineno"> 64</tt> <a class="py-toggle" href="#" id="OAuthSignatureMethod_HMAC_SHA1.get_normalized_http_method-toggle" onclick="return toggle('OAuthSignatureMethod_HMAC_SHA1.get_normalized_http_method');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="scapi.authentication.OAuthSignatureMethod_HMAC_SHA1-class.html#get_normalized_http_method">get_normalized_http_method</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt> <tt class="py-param">request</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="OAuthSignatureMethod_HMAC_SHA1.get_normalized_http_method-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="OAuthSignatureMethod_HMAC_SHA1.get_normalized_http_method-expanded"><a name="L65"></a><tt class="py-lineno"> 65</tt>  <tt class="py-line">        <tt class="py-keyword">return</tt> <tt class="py-name">request</tt><tt class="py-op">.</tt><tt class="py-name">get_method</tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">.</tt><tt class="py-name">upper</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
</div><a name="L66"></a><tt class="py-lineno"> 66</tt>  <tt class="py-line"> </tt>
<a name="L67"></a><tt class="py-lineno"> 67</tt>  <tt class="py-line">    <tt class="py-comment"># parses the url and rebuilds it to be scheme://host/path</tt> </tt>
<a name="OAuthSignatureMethod_HMAC_SHA1.get_normalized_http_url"></a><div id="OAuthSignatureMethod_HMAC_SHA1.get_normalized_http_url-def"><a name="L68"></a><tt class="py-lineno"> 68</tt> <a class="py-toggle" href="#" id="OAuthSignatureMethod_HMAC_SHA1.get_normalized_http_url-toggle" onclick="return toggle('OAuthSignatureMethod_HMAC_SHA1.get_normalized_http_url');">-</a><tt class="py-line"><tt class="py-comment"></tt>    <tt class="py-keyword">def</tt> <a class="py-def-name" href="scapi.authentication.OAuthSignatureMethod_HMAC_SHA1-class.html#get_normalized_http_url">get_normalized_http_url</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt> <tt class="py-param">request</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="OAuthSignatureMethod_HMAC_SHA1.get_normalized_http_url-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="OAuthSignatureMethod_HMAC_SHA1.get_normalized_http_url-expanded"><a name="L69"></a><tt class="py-lineno"> 69</tt>  <tt class="py-line">        <tt class="py-name">url</tt> <tt class="py-op">=</tt> <tt class="py-name">request</tt><tt class="py-op">.</tt><tt class="py-name">get_full_url</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L70"></a><tt class="py-lineno"> 70</tt>  <tt class="py-line">        <tt class="py-name">parts</tt> <tt class="py-op">=</tt> <tt class="py-name">urlparse</tt><tt class="py-op">.</tt><tt class="py-name">urlparse</tt><tt class="py-op">(</tt><tt class="py-name">url</tt><tt class="py-op">)</tt> </tt>
<a name="L71"></a><tt class="py-lineno"> 71</tt>  <tt class="py-line">        <tt class="py-name">url_string</tt> <tt class="py-op">=</tt> <tt class="py-string">'%s://%s%s'</tt> <tt class="py-op">%</tt> <tt class="py-op">(</tt><tt class="py-name">parts</tt><tt class="py-op">.</tt><tt class="py-name">scheme</tt><tt class="py-op">,</tt> <tt class="py-name">parts</tt><tt class="py-op">.</tt><tt class="py-name">netloc</tt><tt class="py-op">,</tt> <tt class="py-name">parts</tt><tt class="py-op">.</tt><tt class="py-name">path</tt><tt class="py-op">)</tt> </tt>
<a name="L72"></a><tt class="py-lineno"> 72</tt>  <tt class="py-line">        <tt class="py-keyword">return</tt> <tt class="py-name">url_string</tt> </tt>
</div><a name="L73"></a><tt class="py-lineno"> 73</tt>  <tt class="py-line"> </tt>
<a name="OAuthSignatureMethod_HMAC_SHA1.get_normalized_parameters"></a><div id="OAuthSignatureMethod_HMAC_SHA1.get_normalized_parameters-def"><a name="L74"></a><tt class="py-lineno"> 74</tt> <a class="py-toggle" href="#" id="OAuthSignatureMethod_HMAC_SHA1.get_normalized_parameters-toggle" onclick="return toggle('OAuthSignatureMethod_HMAC_SHA1.get_normalized_parameters');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="scapi.authentication.OAuthSignatureMethod_HMAC_SHA1-class.html#get_normalized_parameters">get_normalized_parameters</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt> <tt class="py-param">params</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="OAuthSignatureMethod_HMAC_SHA1.get_normalized_parameters-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="OAuthSignatureMethod_HMAC_SHA1.get_normalized_parameters-expanded"><a name="L75"></a><tt class="py-lineno"> 75</tt>  <tt class="py-line">        <tt class="py-keyword">if</tt> <tt class="py-name">params</tt> <tt class="py-keyword">is</tt> <tt class="py-name">None</tt><tt class="py-op">:</tt> </tt>
<a name="L76"></a><tt class="py-lineno"> 76</tt>  <tt class="py-line">            <tt class="py-name">params</tt> <tt class="py-op">=</tt> <tt class="py-op">{</tt><tt class="py-op">}</tt> </tt>
<a name="L77"></a><tt class="py-lineno"> 77</tt>  <tt class="py-line">        <tt class="py-keyword">try</tt><tt class="py-op">:</tt> </tt>
<a name="L78"></a><tt class="py-lineno"> 78</tt>  <tt class="py-line">            <tt class="py-comment"># exclude the signature if it exists</tt> </tt>
<a name="L79"></a><tt class="py-lineno"> 79</tt>  <tt class="py-line"><tt class="py-comment"></tt>            <tt class="py-keyword">del</tt> <tt class="py-name">params</tt><tt class="py-op">[</tt><tt class="py-string">'oauth_signature'</tt><tt class="py-op">]</tt> </tt>
<a name="L80"></a><tt class="py-lineno"> 80</tt>  <tt class="py-line">        <tt class="py-keyword">except</tt><tt class="py-op">:</tt> </tt>
<a name="L81"></a><tt class="py-lineno"> 81</tt>  <tt class="py-line">            <tt class="py-keyword">pass</tt> </tt>
<a name="L82"></a><tt class="py-lineno"> 82</tt>  <tt class="py-line">        <tt class="py-name">key_values</tt> <tt class="py-op">=</tt> <tt class="py-op">[</tt><tt class="py-op">]</tt> </tt>
<a name="L83"></a><tt class="py-lineno"> 83</tt>  <tt class="py-line">         </tt>
<a name="L84"></a><tt class="py-lineno"> 84</tt>  <tt class="py-line">        <tt class="py-keyword">for</tt> <tt class="py-name">key</tt><tt class="py-op">,</tt> <tt class="py-name">values</tt> <tt class="py-keyword">in</tt> <tt class="py-name">params</tt><tt class="py-op">.</tt><tt class="py-name">iteritems</tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L85"></a><tt class="py-lineno"> 85</tt>  <tt class="py-line">            <tt class="py-keyword">if</tt> <tt class="py-name">isinstance</tt><tt class="py-op">(</tt><tt class="py-name">values</tt><tt class="py-op">,</tt> <tt class="py-name">file</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L86"></a><tt class="py-lineno"> 86</tt>  <tt class="py-line">                <tt class="py-keyword">continue</tt> </tt>
<a name="L87"></a><tt class="py-lineno"> 87</tt>  <tt class="py-line">            <tt class="py-keyword">if</tt> <tt class="py-name">isinstance</tt><tt class="py-op">(</tt><tt class="py-name">values</tt><tt class="py-op">,</tt> <tt class="py-op">(</tt><tt class="py-name">int</tt><tt class="py-op">,</tt> <tt class="py-name">long</tt><tt class="py-op">,</tt> <tt class="py-name">float</tt><tt class="py-op">)</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L88"></a><tt class="py-lineno"> 88</tt>  <tt class="py-line">                <tt class="py-name">values</tt> <tt class="py-op">=</tt> <tt class="py-name">str</tt><tt class="py-op">(</tt><tt class="py-name">values</tt><tt class="py-op">)</tt> </tt>
<a name="L89"></a><tt class="py-lineno"> 89</tt>  <tt class="py-line">            <tt class="py-keyword">if</tt> <tt class="py-name">isinstance</tt><tt class="py-op">(</tt><tt class="py-name">values</tt><tt class="py-op">,</tt> <tt class="py-op">(</tt><tt class="py-name">list</tt><tt class="py-op">,</tt> <tt class="py-name">tuple</tt><tt class="py-op">)</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L90"></a><tt class="py-lineno"> 90</tt>  <tt class="py-line">                <tt class="py-name">values</tt> <tt class="py-op">=</tt> <tt class="py-op">[</tt><tt class="py-name">str</tt><tt class="py-op">(</tt><tt class="py-name">v</tt><tt class="py-op">)</tt> <tt class="py-keyword">for</tt> <tt class="py-name">v</tt> <tt class="py-keyword">in</tt> <tt class="py-name">values</tt><tt class="py-op">]</tt> </tt>
<a name="L91"></a><tt class="py-lineno"> 91</tt>  <tt class="py-line">            <tt class="py-keyword">if</tt> <tt class="py-name">isinstance</tt><tt class="py-op">(</tt><tt class="py-name">values</tt><tt class="py-op">,</tt> <tt class="py-name">basestring</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L92"></a><tt class="py-lineno"> 92</tt>  <tt class="py-line">                <tt class="py-name">values</tt> <tt class="py-op">=</tt> <tt class="py-op">[</tt><tt class="py-name">values</tt><tt class="py-op">]</tt> </tt>
<a name="L93"></a><tt class="py-lineno"> 93</tt>  <tt class="py-line">            <tt class="py-keyword">for</tt> <tt class="py-name">v</tt> <tt class="py-keyword">in</tt> <tt class="py-name">values</tt><tt class="py-op">:</tt> </tt>
<a name="L94"></a><tt class="py-lineno"> 94</tt>  <tt class="py-line">                <tt class="py-name">v</tt> <tt class="py-op">=</tt> <tt class="py-name">v</tt><tt class="py-op">.</tt><tt class="py-name">encode</tt><tt class="py-op">(</tt><tt class="py-string">"utf-8"</tt><tt class="py-op">)</tt> </tt>
<a name="L95"></a><tt class="py-lineno"> 95</tt>  <tt class="py-line">                <tt class="py-name">key</tt> <tt class="py-op">=</tt> <tt class="py-name">key</tt><tt class="py-op">.</tt><tt class="py-name">encode</tt><tt class="py-op">(</tt><tt class="py-string">"utf-8"</tt><tt class="py-op">)</tt> </tt>
<a name="L96"></a><tt class="py-lineno"> 96</tt>  <tt class="py-line">                <tt class="py-name">key_values</tt><tt class="py-op">.</tt><tt class="py-name">append</tt><tt class="py-op">(</tt><tt id="link-14" class="py-name"><a title="scapi.util.escape" class="py-name" href="#" onclick="return doclink('link-14', 'escape', 'link-2');">escape</a></tt><tt class="py-op">(</tt><tt class="py-string">"%s=%s"</tt> <tt class="py-op">%</tt> <tt class="py-op">(</tt><tt class="py-name">key</tt><tt class="py-op">,</tt> <tt class="py-name">v</tt><tt class="py-op">)</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
<a name="L97"></a><tt class="py-lineno"> 97</tt>  <tt class="py-line">        <tt class="py-comment"># sort lexicographically, first after key, then after value</tt> </tt>
<a name="L98"></a><tt class="py-lineno"> 98</tt>  <tt class="py-line"><tt class="py-comment"></tt>        <tt class="py-name">key_values</tt><tt class="py-op">.</tt><tt class="py-name">sort</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L99"></a><tt class="py-lineno"> 99</tt>  <tt class="py-line">        <tt class="py-comment"># combine key value pairs in string</tt> </tt>
<a name="L100"></a><tt class="py-lineno">100</tt>  <tt class="py-line"><tt class="py-comment"></tt>        <tt class="py-keyword">return</tt> <tt id="link-15" class="py-name"><a title="scapi.util.escape" class="py-name" href="#" onclick="return doclink('link-15', 'escape', 'link-2');">escape</a></tt><tt class="py-op">(</tt><tt class="py-string">'&amp;'</tt><tt class="py-op">)</tt><tt class="py-op">.</tt><tt class="py-name">join</tt><tt class="py-op">(</tt><tt class="py-name">key_values</tt><tt class="py-op">)</tt> </tt>
</div></div><a name="L101"></a><tt class="py-lineno">101</tt>  <tt class="py-line"> </tt>
<a name="OAuthAuthenticator"></a><div id="OAuthAuthenticator-def"><a name="L102"></a><tt class="py-lineno">102</tt> <a class="py-toggle" href="#" id="OAuthAuthenticator-toggle" onclick="return toggle('OAuthAuthenticator');">-</a><tt class="py-line"><tt class="py-keyword">class</tt> <a class="py-def-name" href="scapi.authentication.OAuthAuthenticator-class.html">OAuthAuthenticator</a><tt class="py-op">(</tt><tt class="py-base-class">object</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="OAuthAuthenticator-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="OAuthAuthenticator-expanded"><a name="L103"></a><tt class="py-lineno">103</tt>  <tt class="py-line">    <tt id="link-16" class="py-name" targets="Variable scapi.authentication.OAuthAuthenticator.OAUTH_API_VERSION=scapi.authentication.OAuthAuthenticator-class.html#OAUTH_API_VERSION"><a title="scapi.authentication.OAuthAuthenticator.OAUTH_API_VERSION" class="py-name" href="#" onclick="return doclink('link-16', 'OAUTH_API_VERSION', 'link-16');">OAUTH_API_VERSION</a></tt> <tt class="py-op">=</tt> <tt class="py-string">'1.0'</tt> </tt>
<a name="L104"></a><tt class="py-lineno">104</tt>  <tt class="py-line">    <tt id="link-17" class="py-name" targets="Variable scapi.authentication.OAuthAuthenticator.AUTHORIZATION_HEADER=scapi.authentication.OAuthAuthenticator-class.html#AUTHORIZATION_HEADER"><a title="scapi.authentication.OAuthAuthenticator.AUTHORIZATION_HEADER" class="py-name" href="#" onclick="return doclink('link-17', 'AUTHORIZATION_HEADER', 'link-17');">AUTHORIZATION_HEADER</a></tt> <tt class="py-op">=</tt> <tt class="py-string">"Authorization"</tt> </tt>
<a name="L105"></a><tt class="py-lineno">105</tt>  <tt class="py-line"> </tt>
<a name="OAuthAuthenticator.__init__"></a><div id="OAuthAuthenticator.__init__-def"><a name="L106"></a><tt class="py-lineno">106</tt> <a class="py-toggle" href="#" id="OAuthAuthenticator.__init__-toggle" onclick="return toggle('OAuthAuthenticator.__init__');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="scapi.authentication.OAuthAuthenticator-class.html#__init__">__init__</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt> <tt class="py-param">consumer</tt><tt class="py-op">,</tt> <tt class="py-param">consumer_secret</tt><tt class="py-op">,</tt> <tt class="py-param">token</tt><tt class="py-op">,</tt> <tt class="py-param">secret</tt><tt class="py-op">,</tt> <tt class="py-param">signature_method</tt><tt class="py-op">=</tt><tt id="link-18" class="py-name" targets="Class scapi.authentication.OAuthSignatureMethod_HMAC_SHA1=scapi.authentication.OAuthSignatureMethod_HMAC_SHA1-class.html"><a title="scapi.authentication.OAuthSignatureMethod_HMAC_SHA1" class="py-name" href="#" onclick="return doclink('link-18', 'OAuthSignatureMethod_HMAC_SHA1', 'link-18');">OAuthSignatureMethod_HMAC_SHA1</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="OAuthAuthenticator.__init__-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="OAuthAuthenticator.__init__-expanded"><a name="L107"></a><tt class="py-lineno">107</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_consumer</tt><tt class="py-op">,</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_token</tt><tt class="py-op">,</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_secret</tt> <tt class="py-op">=</tt> <tt class="py-name">consumer</tt><tt class="py-op">,</tt> <tt class="py-name">token</tt><tt class="py-op">,</tt> <tt class="py-name">secret</tt> </tt>
<a name="L108"></a><tt class="py-lineno">108</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_consumer_secret</tt> <tt class="py-op">=</tt> <tt class="py-name">consumer_secret</tt> </tt>
<a name="L109"></a><tt class="py-lineno">109</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_signature_method</tt> <tt class="py-op">=</tt> <tt class="py-name">signature_method</tt> </tt>
<a name="L110"></a><tt class="py-lineno">110</tt>  <tt class="py-line">        <tt class="py-name">random</tt><tt class="py-op">.</tt><tt class="py-name">seed</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
</div><a name="L111"></a><tt class="py-lineno">111</tt>  <tt class="py-line"> </tt>
<a name="OAuthAuthenticator.augment_request"></a><div id="OAuthAuthenticator.augment_request-def"><a name="L112"></a><tt class="py-lineno">112</tt> <a class="py-toggle" href="#" id="OAuthAuthenticator.augment_request-toggle" onclick="return toggle('OAuthAuthenticator.augment_request');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="scapi.authentication.OAuthAuthenticator-class.html#augment_request">augment_request</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt> <tt class="py-param">req</tt><tt class="py-op">,</tt> <tt class="py-param">parameters</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="OAuthAuthenticator.augment_request-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="OAuthAuthenticator.augment_request-expanded"><a name="L113"></a><tt class="py-lineno">113</tt>  <tt class="py-line">        <tt class="py-name">oauth_parameters</tt> <tt class="py-op">=</tt> <tt class="py-op">{</tt> </tt>
<a name="L114"></a><tt class="py-lineno">114</tt>  <tt class="py-line">            <tt class="py-string">'oauth_consumer_key'</tt><tt class="py-op">:</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_consumer</tt><tt class="py-op">,</tt> </tt>
<a name="L115"></a><tt class="py-lineno">115</tt>  <tt class="py-line">            <tt class="py-string">'oauth_timestamp'</tt><tt class="py-op">:</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-19" class="py-name" targets="Method scapi.authentication.OAuthAuthenticator.generate_timestamp()=scapi.authentication.OAuthAuthenticator-class.html#generate_timestamp"><a title="scapi.authentication.OAuthAuthenticator.generate_timestamp" class="py-name" href="#" onclick="return doclink('link-19', 'generate_timestamp', 'link-19');">generate_timestamp</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">,</tt> </tt>
<a name="L116"></a><tt class="py-lineno">116</tt>  <tt class="py-line">            <tt class="py-string">'oauth_nonce'</tt><tt class="py-op">:</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-20" class="py-name" targets="Method scapi.authentication.OAuthAuthenticator.generate_nonce()=scapi.authentication.OAuthAuthenticator-class.html#generate_nonce"><a title="scapi.authentication.OAuthAuthenticator.generate_nonce" class="py-name" href="#" onclick="return doclink('link-20', 'generate_nonce', 'link-20');">generate_nonce</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">,</tt> </tt>
<a name="L117"></a><tt class="py-lineno">117</tt>  <tt class="py-line">            <tt class="py-string">'oauth_version'</tt><tt class="py-op">:</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-21" class="py-name"><a title="scapi.authentication.OAuthAuthenticator.OAUTH_API_VERSION" class="py-name" href="#" onclick="return doclink('link-21', 'OAUTH_API_VERSION', 'link-16');">OAUTH_API_VERSION</a></tt><tt class="py-op">,</tt> </tt>
<a name="L118"></a><tt class="py-lineno">118</tt>  <tt class="py-line">            <tt class="py-string">'oauth_signature_method'</tt> <tt class="py-op">:</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_signature_method</tt><tt class="py-op">.</tt><tt id="link-22" class="py-name" targets="Method scapi.authentication.OAuthSignatureMethod_HMAC_SHA1.get_name()=scapi.authentication.OAuthSignatureMethod_HMAC_SHA1-class.html#get_name"><a title="scapi.authentication.OAuthSignatureMethod_HMAC_SHA1.get_name" class="py-name" href="#" onclick="return doclink('link-22', 'get_name', 'link-22');">get_name</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">,</tt> </tt>
<a name="L119"></a><tt class="py-lineno">119</tt>  <tt class="py-line">            <tt class="py-comment">#'realm' : "http://soundcloud.com",</tt> </tt>
<a name="L120"></a><tt class="py-lineno">120</tt>  <tt class="py-line">            <tt class="py-op">}</tt> </tt>
<a name="L121"></a><tt class="py-lineno">121</tt>  <tt class="py-line">        <tt class="py-keyword">if</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_token</tt> <tt class="py-keyword">is</tt> <tt class="py-keyword">not</tt> <tt class="py-name">None</tt><tt class="py-op">:</tt> </tt>
<a name="L122"></a><tt class="py-lineno">122</tt>  <tt class="py-line">            <tt class="py-name">oauth_parameters</tt><tt class="py-op">[</tt><tt class="py-string">'oauth_token'</tt><tt class="py-op">]</tt> <tt class="py-op">=</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_token</tt> </tt>
<a name="L123"></a><tt class="py-lineno">123</tt>  <tt class="py-line"> </tt>
<a name="L124"></a><tt class="py-lineno">124</tt>  <tt class="py-line">        <tt class="py-name">oauth_parameters</tt><tt class="py-op">[</tt><tt class="py-string">'oauth_signature'</tt><tt class="py-op">]</tt> <tt class="py-op">=</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_signature_method</tt><tt class="py-op">.</tt><tt id="link-23" class="py-name" targets="Method scapi.authentication.OAuthSignatureMethod_HMAC_SHA1.build_signature()=scapi.authentication.OAuthSignatureMethod_HMAC_SHA1-class.html#build_signature"><a title="scapi.authentication.OAuthSignatureMethod_HMAC_SHA1.build_signature" class="py-name" href="#" onclick="return doclink('link-23', 'build_signature', 'link-23');">build_signature</a></tt><tt class="py-op">(</tt><tt class="py-name">req</tt><tt class="py-op">,</tt>  </tt>
<a name="L125"></a><tt class="py-lineno">125</tt>  <tt class="py-line">                                                                                     <tt class="py-name">parameters</tt><tt class="py-op">,</tt>  </tt>
<a name="L126"></a><tt class="py-lineno">126</tt>  <tt class="py-line">                                                                                     <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_consumer_secret</tt><tt class="py-op">,</tt>  </tt>
<a name="L127"></a><tt class="py-lineno">127</tt>  <tt class="py-line">                                                                                     <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_secret</tt><tt class="py-op">,</tt>  </tt>
<a name="L128"></a><tt class="py-lineno">128</tt>  <tt class="py-line">                                                                                     <tt class="py-name">oauth_parameters</tt><tt class="py-op">)</tt> </tt>
<a name="L129"></a><tt class="py-lineno">129</tt>  <tt class="py-line">        <tt class="py-keyword">def</tt> <tt class="py-def-name">to_header</tt><tt class="py-op">(</tt><tt class="py-param">d</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L130"></a><tt class="py-lineno">130</tt>  <tt class="py-line">            <tt class="py-keyword">return</tt> <tt class="py-string">","</tt><tt class="py-op">.</tt><tt class="py-name">join</tt><tt class="py-op">(</tt><tt class="py-string">'%s="%s"'</tt> <tt class="py-op">%</tt> <tt class="py-op">(</tt><tt class="py-name">key</tt><tt class="py-op">,</tt> <tt class="py-name">value</tt><tt class="py-op">)</tt> <tt class="py-keyword">for</tt> <tt class="py-name">key</tt><tt class="py-op">,</tt> <tt class="py-name">value</tt> <tt class="py-keyword">in</tt> <tt class="py-name">sorted</tt><tt class="py-op">(</tt><tt class="py-name">oauth_parameters</tt><tt class="py-op">.</tt><tt class="py-name">items</tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
</div><a name="L131"></a><tt class="py-lineno">131</tt>  <tt class="py-line"> </tt>
<a name="L132"></a><tt class="py-lineno">132</tt>  <tt class="py-line">        <tt class="py-name">req</tt><tt class="py-op">.</tt><tt class="py-name">add_header</tt><tt class="py-op">(</tt><tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-24" class="py-name"><a title="scapi.authentication.OAuthAuthenticator.AUTHORIZATION_HEADER" class="py-name" href="#" onclick="return doclink('link-24', 'AUTHORIZATION_HEADER', 'link-17');">AUTHORIZATION_HEADER</a></tt><tt class="py-op">,</tt> <tt class="py-string">"OAuth  %s"</tt> <tt class="py-op">%</tt> <tt class="py-name">to_header</tt><tt class="py-op">(</tt><tt class="py-name">oauth_parameters</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
</div><a name="L133"></a><tt class="py-lineno">133</tt>  <tt class="py-line"> </tt>
<a name="OAuthAuthenticator.generate_timestamp"></a><div id="OAuthAuthenticator.generate_timestamp-def"><a name="L134"></a><tt class="py-lineno">134</tt> <a class="py-toggle" href="#" id="OAuthAuthenticator.generate_timestamp-toggle" onclick="return toggle('OAuthAuthenticator.generate_timestamp');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="scapi.authentication.OAuthAuthenticator-class.html#generate_timestamp">generate_timestamp</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="OAuthAuthenticator.generate_timestamp-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="OAuthAuthenticator.generate_timestamp-expanded"><a name="L135"></a><tt class="py-lineno">135</tt>  <tt class="py-line">        <tt class="py-keyword">return</tt> <tt class="py-name">int</tt><tt class="py-op">(</tt><tt class="py-name">time</tt><tt class="py-op">.</tt><tt class="py-name">time</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> <tt class="py-op">*</tt> <tt class="py-number">1000.0</tt><tt class="py-op">)</tt> </tt>
</div><a name="L136"></a><tt class="py-lineno">136</tt>  <tt class="py-line"> </tt>
<a name="OAuthAuthenticator.generate_nonce"></a><div id="OAuthAuthenticator.generate_nonce-def"><a name="L137"></a><tt class="py-lineno">137</tt> <a class="py-toggle" href="#" id="OAuthAuthenticator.generate_nonce-toggle" onclick="return toggle('OAuthAuthenticator.generate_nonce');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="scapi.authentication.OAuthAuthenticator-class.html#generate_nonce">generate_nonce</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt> <tt class="py-param">length</tt><tt class="py-op">=</tt><tt class="py-number">8</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="OAuthAuthenticator.generate_nonce-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="OAuthAuthenticator.generate_nonce-expanded"><a name="L138"></a><tt class="py-lineno">138</tt>  <tt class="py-line">        <tt class="py-keyword">return</tt> <tt class="py-string">''</tt><tt class="py-op">.</tt><tt class="py-name">join</tt><tt class="py-op">(</tt><tt class="py-name">str</tt><tt class="py-op">(</tt><tt class="py-name">random</tt><tt class="py-op">.</tt><tt class="py-name">randint</tt><tt class="py-op">(</tt><tt class="py-number">0</tt><tt class="py-op">,</tt> <tt class="py-number">9</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> <tt class="py-keyword">for</tt> <tt class="py-name">i</tt> <tt class="py-keyword">in</tt> <tt class="py-name">range</tt><tt class="py-op">(</tt><tt class="py-name">length</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
</div></div><a name="L139"></a><tt class="py-lineno">139</tt>  <tt class="py-line"> </tt>
<a name="BasicAuthenticator"></a><div id="BasicAuthenticator-def"><a name="L140"></a><tt class="py-lineno">140</tt> <a class="py-toggle" href="#" id="BasicAuthenticator-toggle" onclick="return toggle('BasicAuthenticator');">-</a><tt class="py-line"><tt class="py-keyword">class</tt> <a class="py-def-name" href="scapi.authentication.BasicAuthenticator-class.html">BasicAuthenticator</a><tt class="py-op">(</tt><tt class="py-base-class">object</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="BasicAuthenticator-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="BasicAuthenticator-expanded"><a name="L141"></a><tt class="py-lineno">141</tt>  <tt class="py-line">     </tt>
<a name="BasicAuthenticator.__init__"></a><div id="BasicAuthenticator.__init__-def"><a name="L142"></a><tt class="py-lineno">142</tt> <a class="py-toggle" href="#" id="BasicAuthenticator.__init__-toggle" onclick="return toggle('BasicAuthenticator.__init__');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="scapi.authentication.BasicAuthenticator-class.html#__init__">__init__</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt> <tt class="py-param">user</tt><tt class="py-op">,</tt> <tt class="py-param">password</tt><tt class="py-op">,</tt> <tt class="py-param">consumer</tt><tt class="py-op">,</tt> <tt class="py-param">consumer_secret</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="BasicAuthenticator.__init__-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="BasicAuthenticator.__init__-expanded"><a name="L143"></a><tt class="py-lineno">143</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_base64string</tt> <tt class="py-op">=</tt> <tt class="py-name">base64</tt><tt class="py-op">.</tt><tt class="py-name">encodestring</tt><tt class="py-op">(</tt><tt class="py-string">"%s:%s"</tt> <tt class="py-op">%</tt> <tt class="py-op">(</tt><tt class="py-name">user</tt><tt class="py-op">,</tt> <tt class="py-name">password</tt><tt class="py-op">)</tt><tt class="py-op">)</tt><tt class="py-op">[</tt><tt class="py-op">:</tt><tt class="py-op">-</tt><tt class="py-number">1</tt><tt class="py-op">]</tt> </tt>
<a name="L144"></a><tt class="py-lineno">144</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_x_auth_header</tt> <tt class="py-op">=</tt> <tt class="py-string">'OAuth oauth_consumer_key="%s" oauth_consumer_secret="%s"'</tt> <tt class="py-op">%</tt> <tt class="py-op">(</tt><tt class="py-name">consumer</tt><tt class="py-op">,</tt> <tt class="py-name">consumer_secret</tt><tt class="py-op">)</tt> </tt>
</div><a name="L145"></a><tt class="py-lineno">145</tt>  <tt class="py-line"> </tt>
<a name="BasicAuthenticator.augment_request"></a><div id="BasicAuthenticator.augment_request-def"><a name="L146"></a><tt class="py-lineno">146</tt> <a class="py-toggle" href="#" id="BasicAuthenticator.augment_request-toggle" onclick="return toggle('BasicAuthenticator.augment_request');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="scapi.authentication.BasicAuthenticator-class.html#augment_request">augment_request</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt> <tt class="py-param">req</tt><tt class="py-op">,</tt> <tt class="py-param">parameters</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="BasicAuthenticator.augment_request-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="BasicAuthenticator.augment_request-expanded"><a name="L147"></a><tt class="py-lineno">147</tt>  <tt class="py-line">        <tt class="py-name">req</tt><tt class="py-op">.</tt><tt class="py-name">add_header</tt><tt class="py-op">(</tt><tt class="py-string">"Authorization"</tt><tt class="py-op">,</tt> <tt class="py-string">"Basic %s"</tt> <tt class="py-op">%</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_base64string</tt><tt class="py-op">)</tt> </tt>
<a name="L148"></a><tt class="py-lineno">148</tt>  <tt class="py-line">        <tt class="py-name">req</tt><tt class="py-op">.</tt><tt class="py-name">add_header</tt><tt class="py-op">(</tt><tt class="py-string">"X-Authorization"</tt><tt class="py-op">,</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">_x_auth_header</tt><tt class="py-op">)</tt> </tt>
</div></div><a name="L149"></a><tt class="py-lineno">149</tt>  <tt class="py-line"> </tt><script type="text/javascript">
<!--
expandto(location.href);
// -->
</script>
</pre>
<br />
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="scapi-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            >SoundCloud API</th>
          </tr></table></th>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
  <tr>
    <td align="left" class="footer">
    Generated by Epydoc 3.0beta1 on Fri Apr 18 16:28:19 2008
    </td>
    <td align="right" class="footer">
      <a href="http://epydoc.sourceforge.net">http://epydoc.sourceforge.net</a>
    </td>
  </tr>
</table>

<script type="text/javascript">
  <!--
  // Private objects are initially displayed (because if
  // javascript is turned off then we want them to be
  // visible); but by default, we want to hide them.  So hide
  // them unless we have a cookie that says to show them.
  checkCookie()
  // -->
</script>
  
</body>
</html>
